﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AzureBlob
{
    /// <summary>
    /// Interaction logic for CacheControlDialog.xaml
    /// </summary>
    public partial class CacheControlDialog : Window
    {
        public CacheControlDialog()
        {
            InitializeComponent();
            CheckAvailbility();
        }

        public string CacheControlString
        {
            set
            {
                if (value != null && value.StartsWith("max-age="))
                    textBox1.Text = value.Substring(8);
                else
                    textBox1.Text = string.Empty;
                CheckAvailbility();
            }
            get
            {
                return "max-age=" + textBox1.Text.Trim();
            }
        }

        private void Okbtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            CheckAvailbility();
        }

        private void CheckAvailbility()
        {
            foreach (char c in textBox1.Text)
            {
                if (c < '0' || '9' < c)
                {
                    Okbtn.IsEnabled = false;
                    return;
                }
            }
            Okbtn.IsEnabled = true;
        }
    }
}
